package basic;

import java.util.LinkedList;
import misc.BasicWorldOperations;

public class World implements BasicWorldOperations{
	
	private LinkedList<Country> countries = null;
	
	public World() {
		super();
		this.countries = new LinkedList<Country>();
	}

	public World(LinkedList<Country> countries) {
		super();
		this.countries = countries;
	}

	@Override
	public void addCountry(String name) {
		Country country = new Country(name);
		countries.add(country);
	}

	@Override
	public void removeCountry(String name) {
		for (int i = 0; i < countries.size(); i++) {
			if (countries.get(i).getName().equals(name))
				countries.remove(i);
		}
	}
	
	public Country[] getCountries() {
		Country[] countriesArray = new Country[countries.size()];
		for (int i = 0; i < countries.size(); i++){
			countriesArray[i] = countries.get(i);
		}
		return countriesArray;
	}
	public Country getCountry(String name){
		for (int i = 0; i < countries.size(); i++){
			if(countries.get(i).getName().equals(name))
				return countries.get(i);
		}
		return null;
	}

}
